package extend_widget

import (
	"clientDemo/ui/fyne_ui/common"
	"clientDemo/ui/fyne_ui/widget/interface"
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/driver/desktop"
	widget2 "fyne.io/fyne/v2/widget"
)

var _ desktop.Hoverable = (*holdableButton)(nil)

type holdableButton struct {
	*widget2.Button
	*Action
	*Container
	name string
	widgetcommon.IUserInfo
	rootNode widgetcommon.IWidgetItem //父节点
}

func NewHoldableButton(label string, skinInfo widgetcommon.IWidgetSkin, rootNode widgetcommon.IWidgetItem) widgetcommon.IWidgetItem {
	if skinInfo == nil {
		return nil
	}
	o := widget2.NewButton(label, func() {

	})
	button := &holdableButton{
		name:   label,
		Button: o,
		Action: &Action{},
		Container: &Container{
			name: label,
		},
		rootNode: rootNode,
	}
	button.IUserInfo = common.NewWidgetUserInfo(label, skinInfo.GetSkinName(), button)
	button.SetBase(button, rootNode)
	button.ExtendBaseWidget(button)
	button.Text = label
	return button
}

func (h *holdableButton) MouseMoved(event *desktop.MouseEvent) {
	h.Action.MouseMoved(event)
	h.Refresh()
}
func (h *holdableButton) MouseIn(event *desktop.MouseEvent) {
	h.Action.MouseIn(event)
}
func (h *holdableButton) MouseOut() {
	h.Action.MouseOut()
}

func (h *holdableButton) ForEach(cb func(objects widgetcommon.IWidgetItem) bool) {

}
func (h *holdableButton) SetMinSize(size fyne.Size) {
}

func (h *holdableButton) Move2(pos fyne.Position) {

}

//
//func (h *holdableButton) MouseDown(ev *desktop.MouseEvent) {
//	log.Println("[holdableButton]down")
//}
//func (h *holdableButton) MouseUp(ev *desktop.MouseEvent) {
//	log.Println("[holdableButton]up")
//}
//
//func (h *holdableButton) MouseMoved(event *desktop.MouseEvent) {
//	X, Y := event.Position.X, event.Position.Y
//	log.Printf("[holdableButton]MouseMoved %v  %v", X, Y)
//	h.Refresh()
//}
